package nl.sportan.samenloop.communication.flickr;

import java.io.IOException;

import nl.sportan.samenloop.communication.PhotoListTarget;

import org.json.JSONException;

import com.gmail.yuyang226.flickr.Flickr;
import com.gmail.yuyang226.flickr.FlickrException;
import com.gmail.yuyang226.flickr.photos.PhotoList;
import com.gmail.yuyang226.flickr.photosets.Photoset;
import com.gmail.yuyang226.flickr.photosets.PhotosetsInterface;

public class FrontPageRetriever implements Runnable {
	Flickr f = new Flickr(FlickrConstants.APIKEY);

	PhotoListTarget target;

	public FrontPageRetriever(PhotoListTarget target) {
		this.target = target;
	}

	public void run() {
		PhotosetsInterface psi = f.getPhotosetsInterface();
		PhotoList photos;
		try {
			Photoset ps = psi.getInfo(FlickrConstants.FRONT_PAGE);

			photos = psi.getPhotos(ps.getId(), ps.getPhotoCount(), 1);

			target.setPhotoList(photos);
		} catch (FlickrException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}